//package com.scrcu.core.common.serv.service.impl;
//
//import org.springframework.beans.factory.annotation.Autowired;
//import org.springframework.stereotype.Component;
//import org.springframework.transaction.annotation.Propagation;
//import org.springframework.transaction.annotation.Transactional;
//
//import com.boarsoft.boar.sequence.service.SequenceService;
//import com.boarsoft.config.spring.util.SpringContextUtil;
//import com.scrcu.core.common.serv.component.impl.ReverseNumSelector;
//import com.scrcu.core.common.serv.component.impl.SegmentSelector;
//import com.scrcu.core.common.serv.component.impl.SingleSelector;
//import com.scrcu.core.common.serv.component.impl.SingleSeqBacker;
//import com.scrcu.core.common.serv.dal.daointerface.sequence.SequenceInfoDao;
//import com.scrcu.core.common.serv.dal.dataobject.sequence.SequenceInfoDO;
//import com.scrcu.core.common.serv.model.SeqSegDTO;
//
//@Component("sequenceService")
//public class SequenceServiceImpl implements SequenceService {
//	@Autowired
//	SequenceInfoDao sequenceInfoDao;
//
//	public SeqSegDTO getSegment(String uid, String seqName, String tag) {
//		SequenceInfoDO sequenceInfoDO = this.sequenceInfoDao.getSeqInfoWithLock(seqName);
//		if (sequenceInfoDO == null) {
//			throw new RuntimeException("未配置序列[" + seqName + "]！");
//		} else if (!"2".equals(sequenceInfoDO.getType()) && !"1".equals(sequenceInfoDO.getType())) {
//			throw new RuntimeException("该序列非分段类型！");
//		} else {
//			return ((SegmentSelector) SpringContextUtil.getBean(SegmentSelector.class)).selectSequence(seqName, tag,
//					sequenceInfoDO);
//		}
//	}
//
//	@Transactional(propagation = Propagation.REQUIRED, rollbackFor = {Exception.class})
//	public long next(String uid, String seqName) {
//		SequenceInfoDO sequenceInfoDO = this.sequenceInfoDao.getSeqInfoWithLock(seqName);
//		if (sequenceInfoDO == null) {
//			sequenceInfoDO = new SequenceInfoDO();
//			sequenceInfoDO.setSeqName(seqName);
//			sequenceInfoDO.setCurrentValue(1);
//			sequenceInfoDO.setStep(1);
//			sequenceInfoDO.setType("3");
//			this.sequenceInfoDao.insert(sequenceInfoDO);
//		}
//
//		if (!"3".equals(sequenceInfoDO.getType())) {
//			throw new RuntimeException("该序列为分段类型！");
//		} else {
//			return ((SingleSelector) SpringContextUtil.getBean(SingleSelector.class))
//					.selectSequence(seqName, (String) null, sequenceInfoDO).getCurrentNo();
//		}
//	}
//
//	public long take(String uid, String seqName) {
//		SequenceInfoDO sequenceInfoDO = this.sequenceInfoDao.getSeqInfoWithLock(seqName);
//		if (sequenceInfoDO == null) {
//			throw new RuntimeException("未配置序列[" + seqName + "]！");
//		} else {
//			SeqSegDTO seqReverseDTO = ((ReverseNumSelector) SpringContextUtil.getBean(ReverseNumSelector.class))
//					.selectSequence(seqName, (String) null, sequenceInfoDO);
//			return seqReverseDTO != null
//					? seqReverseDTO.getCurrentNo()
//					: ((SingleSelector) SpringContextUtil.getBean(SingleSelector.class))
//							.selectSequence(seqName, (String) null, sequenceInfoDO).getCurrentNo();
//		}
//	}
//
//	public void back(String uid, String seqName, long no) {
//		((SingleSeqBacker) SpringContextUtil.getBean(SingleSeqBacker.class)).back(seqName, no);
//	}
//
//	@Transactional(propagation = Propagation.REQUIRED, rollbackFor = {Exception.class})
//	public long next(String uid, String seqName, String selNum) {
//		SequenceInfoDO sequenceInfoDO = this.sequenceInfoDao.getSeqInfoWithLock(seqName);
//		if (sequenceInfoDO == null) {
//			throw new RuntimeException("该序列名称未在系统中配置！");
//		} else if (!"3".equals(sequenceInfoDO.getType())) {
//			throw new RuntimeException("该序列为分段类型！");
//		} else {
//			return ((SingleSelector) SpringContextUtil.getBean(SingleSelector.class))
//					.selectSequence(seqName, selNum, sequenceInfoDO).getCurrentNo();
//		}
//	}
//}